package com.zzyl.service.impl;


import com.zzyl.dto.BedDto;
import com.zzyl.dto.FloorDto;
import com.zzyl.entity.Floor;
import com.zzyl.mapper.FloorMapper;
import com.zzyl.service.BedService;
import com.zzyl.service.FloorService;
import com.zzyl.service.RoomService;
import com.zzyl.vo.FloorVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.core.Local;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;


@Service

public class FloorServiceImpl implements FloorService {

    @Autowired
    RoomService roomService;

    @Autowired
    BedService bedService;

    @Autowired
    private FloorMapper floorMapper;

    @Override
    public List<FloorVo> getAllWithRoomAndBed() {
        return floorMapper.selectAllRoomAndBed();
    }

    @Override
    public List<FloorVo> selectAllByNur() {
        return floorMapper.selectAllByNur();
    }

    @Override
    public List<FloorVo> getAll() {
        return floorMapper.getAll();
    }

    @Override
    public int add(FloorDto floorDto) {
        Floor floor = new Floor();
        BeanUtils.copyProperties(floorDto,floor);
        floor.setCreateTime(LocalDateTime.now());
        floor.setUpdateTime(LocalDateTime.now());
        floor.setCreateBy(1l);
        floor.setUpdateBy(1l);
        floor.setRemark(null);
        return floorMapper.add(floor);
    }

    @Override
    public int deleteFloor(Long id) {
        return floorMapper.deleteFloor(id);
    }

    @Override
    public int updateFloor(FloorDto floorDto) {
        Floor floor = new Floor();
        BeanUtils.copyProperties(floorDto,floor);
        floor.setUpdateBy(1l);
        floor.setUpdateTime(LocalDateTime.now());
        return floorMapper.updateFloor(floor);
    }

    @Override
    public FloorVo readFloor(Long id) {
        Floor floor = floorMapper.readFloor(id);
        FloorVo floorVo = new FloorVo();
        BeanUtils.copyProperties(floor,floorVo);
        return floorVo;
    }

}

